﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Taxonomy;
using System.Diagnostics;

namespace XComplica.SharePoint
{
    public class TaxonomyFieldValueComparer : IEqualityComparer<TaxonomyFieldValue>
    {
        public bool Equals(TaxonomyFieldValue x, TaxonomyFieldValue y)
        {
            if (null != x && null != y)
            {
                bool outcome = x.TermGuid == y.TermGuid;
                Debug.WriteLine(string.Format("Comparing {0} and {1} outcome {2}", x, y, outcome));
                return outcome;
            }
            else if (null == x && null == y)
                return true;
            else
                return false;
        }

        public int GetHashCode(TaxonomyFieldValue obj)
        {
            if (null != obj && !string.IsNullOrEmpty(obj.TermGuid))
                return obj.TermGuid.GetHashCode();
            else
                return base.GetHashCode();
        }
    }
}
